import { _decorator, Component, Label, Node } from 'cc';
import { MapZone } from '../entity/MapZone';
import { raceName } from '../settings/const';
import { Village } from '../entity/Village';
import { PrefabEnum } from '../common/PrefabEnum';
import { UIManager } from '../common/UIManager';
import { ArmyIndex } from '../army/ArmyIndex';
import { BattleLayout } from '../army/BattleLayout';
const { ccclass, property } = _decorator;

@ccclass('PanelOasisOccupy')
export class PanelOasisOccupy extends Component {
    @property(Label)
    public oaRace: Label; // 被占领的绿洲的种族
    @property(Label)
    public oaAlly: Label;// 被占领的绿洲的联盟
    @property(Label)
    public oaOwner: Label;// 被占领的绿洲的所有者
    @property(Label)
    public oaVillage: Label;// 被占领的绿洲的村庄
    @property(Node)
    public battle:Node

    private villageData:Village
    private zone:MapZone
    start() {
        this.battle.on(Node.EventType.TOUCH_END, this.onBattle, this)
    }

    setData(zone:MapZone, data:Village){
        this.zone = zone
        this.villageData = data

        this.oaRace.string = raceName[data.user.uInfo.race]
        this.oaAlly.string = data.user.allyName
        this.oaOwner.string = data.user.uInfo.name
        this.oaVillage.string = data.name
    }

    async onBattle(){
        let ui = await UIManager.instance.openUI(PrefabEnum.ArmyIndex)
        let armyIndex = ui.getComponent(ArmyIndex)
        armyIndex.onBattle()
        let bl = armyIndex.content.children[0].getComponent(BattleLayout)
        bl.onTargetVillage(this.villageData)
    }
}


